package com.ruoyi.swTemp.swTemp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.swTemp.swTemp.domain.SwTemp;
import com.ruoyi.swTemp.swTemp.service.ISwTempService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sw模板Controller
 * 
 * @author ruoyi
 * @date 2025-04-11
 */
@RestController
@RequestMapping("/swTemp/swTemp")
public class SwTempController extends BaseController
{
    @Autowired
    private ISwTempService swTempService;

    /**
     * 查询sw模板列表
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:list')")
    @GetMapping("/list")
    public TableDataInfo list(SwTemp swTemp)
    {
//        System.out.println(swTemp);
        startPage();
        List<SwTemp> list = swTempService.selectSwTempList(swTemp);
        return getDataTable(list);
    }

    /**
     * 导出sw模板列表
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:export')")
    @Log(title = "sw模板", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SwTemp swTemp)
    {
        List<SwTemp> list = swTempService.selectSwTempList(swTemp);
        ExcelUtil<SwTemp> util = new ExcelUtil<SwTemp>(SwTemp.class);
        util.exportExcel(response, list, "sw模板数据");
    }

    /**
     * 获取sw模板详细信息
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(swTempService.selectSwTempById(id));
    }

    /**
     * 新增sw模板
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:add')")
    @Log(title = "sw模板", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SwTemp swTemp)
    {
        return toAjax(swTempService.insertSwTemp(swTemp));
    }

    /**
     * 修改sw模板
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:edit')")
    @Log(title = "sw模板", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SwTemp swTemp)
    {
        return toAjax(swTempService.updateSwTemp(swTemp));
    }

    /**
     * 删除sw模板
     */
    @PreAuthorize("@ss.hasPermi('swTemp:swTemp:remove')")
    @Log(title = "sw模板", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(swTempService.deleteSwTempByIds(ids));
    }
}
